package com.iwop.moto.utils.weixin;

import com.iwop.moto.utils.http.HttpUtils;
import com.iwop.moto.utils.stringUtil.JsonUtils;
import com.iwop.moto.utils.weixin.model.TemplateData;
import com.iwop.moto.utils.weixin.model.WxTemplate;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by liuwb on 2016/8/25.
 */
public class SendModelMsg {

    /**
     * @功能: 服务商身份认证模板通知
     * @日期: liuwb by 2016-08-25 11:50 on create
     * @param openid 发送给微信用户的 openid
     * @param token  微信授权access_token
     * @param isAgreed true 同意 or  false 拒绝
     */
    public static String fwsjmModelMsg(String openid,String token, boolean isAgreed) throws UnsupportedEncodingException {
        WxTemplate wxTmep = new WxTemplate();
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
        wxTmep.setTouser(openid);
        wxTmep.setTemplate_id("94_pGY0XIiQP2XDrw7I0RlvSF_sQS-3Yg5fGRV98DfE");
        wxTmep.setUrl("");
        wxTmep.setTopcolor("#000000");
        Map<String,TemplateData> mTemp = new HashMap<String,TemplateData>();
        // first
        TemplateData first = new TemplateData();
        if(isAgreed){
            first.setValue("平台审核通过");
        }else{
            first.setValue("平台的审核不通过");
        }
        first.setColor("#000000");
        mTemp.put("first", first);
        //keyword1
        TemplateData keyword1 = new TemplateData();
        keyword1.setValue("[服务商加盟审核]");
        keyword1.setColor("#000000");
        mTemp.put("keyword1",keyword1);
        //keyword2
        TemplateData keyword2 = new TemplateData();
        if(isAgreed){
            keyword2.setValue("审核通过");
        }else{
            keyword2.setValue("审核拒绝");
        }
        keyword2.setColor("#000000");
        mTemp.put("keyword2",keyword2);
        //keyword3
        TemplateData keyword3 = new TemplateData();
        keyword3.setValue("0592-5918919");
        keyword3.setColor("#000000");
        mTemp.put("keyword3",keyword3);
        //remark
        TemplateData remark = new TemplateData();
        if(isAgreed) {
            remark.setValue("欢迎您加入开摩邦");
        }else {
            remark.setValue("请确认您的审核资料如有疑议请咨询客服电话");
        }
        remark.setColor("#000000");
        mTemp.put("remark", remark);
        wxTmep.setData(mTemp);
        String jsonTemp = JsonUtils.toJsonString(wxTmep);
        jsonTemp = new String(jsonTemp.getBytes("utf-8"));
        String result = HttpUtils.sendPost(url, jsonTemp);
        return result;
    }

    /**
     * @功能: 维修店提交服务商审核通知模板
     * @日期: liuwb by 2016-08-25 11:53 on Create
     * @param openid 发送给微信用户的 openid
     * @param token  微信授权access_token
     * @param isAgreed true 同意 or  false 拒绝
     */
    public static String wxdsqModelMsg(String openid,String token, boolean isAgreed) throws UnsupportedEncodingException {
        WxTemplate wxTmep = new WxTemplate();
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
        wxTmep.setTouser(openid);
        wxTmep.setTemplate_id("94_pGY0XIiQP2XDrw7I0RlvSF_sQS-3Yg5fGRV98DfE");
        wxTmep.setUrl("");
        wxTmep.setTopcolor("#000000");
        Map<String,TemplateData> mTemp = new HashMap<String,TemplateData>();
        // first
        TemplateData first = new TemplateData();
        if(isAgreed){
            first.setValue("服务商审核已通过");
        }else{
            first.setValue("服务商审核不通过");
        }
        first.setColor("#000000");
        mTemp.put("first", first);
        //keyword1
        TemplateData keyword1 = new TemplateData();
        keyword1.setValue("[维修店加盟审核]");
        keyword1.setColor("#000000");
        mTemp.put("keyword1",keyword1);
        //keyword2
        TemplateData keyword2 = new TemplateData();
        if(isAgreed){
            keyword2.setValue("审核通过");
        }else{
            keyword2.setValue("审核拒绝");
        }
        keyword2.setColor("#000000");
        mTemp.put("keyword2",keyword2);
        //keyword3
        TemplateData keyword3 = new TemplateData();
        keyword3.setValue("0592-5918919");
        keyword3.setColor("#000000");
        mTemp.put("keyword3",keyword3);
        //remark
        TemplateData remark = new TemplateData();
        if(isAgreed) {
            remark.setValue("[服务商审核已通过请等待平台确认]");
        }else {
            remark.setValue("请确认您的审核资料有疑议请咨询相应服务商");
        }
        remark.setColor("#000000");
        mTemp.put("remark", remark);
        wxTmep.setData(mTemp);
        String jsonTemp = JsonUtils.toJsonString(wxTmep);
        jsonTemp = new String(jsonTemp.getBytes("utf-8"));
        String result = HttpUtils.sendPost(url, jsonTemp);
        return result;
    }

    /**
     * @功能: 维修店提交给平台审核
     * @日期: liuwb by 2016-08-25 13:30 on create
     * @param openid 发送给微信用户的 openid
     * @param token  微信授权access_token
     * @param isAgreed true 同意 or  false 拒绝
     */
    public static String wxdsqPtModelMsg(String openid,String token, boolean isAgreed) throws UnsupportedEncodingException {
        WxTemplate wxTmep = new WxTemplate();
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
        wxTmep.setTouser(openid);
        wxTmep.setTemplate_id("94_pGY0XIiQP2XDrw7I0RlvSF_sQS-3Yg5fGRV98DfE");
        wxTmep.setUrl("");
        wxTmep.setTopcolor("#000000");
        Map<String,TemplateData> mTemp = new HashMap<String,TemplateData>();
        // first
        TemplateData first = new TemplateData();
        if(isAgreed){
            first.setValue("平台审核通过");
        }else{
            first.setValue("平台的审核不通过");
        }
        first.setColor("#000000");
        mTemp.put("first", first);
        //keyword1
        TemplateData keyword1 = new TemplateData();
        keyword1.setValue("[维修店加盟审核]");
        keyword1.setColor("#000000");
        mTemp.put("keyword1",keyword1);
        //keyword2
        TemplateData keyword2 = new TemplateData();
        if(isAgreed){
            keyword2.setValue("审核通过");
        }else{
            keyword2.setValue("审核拒绝");
        }
        keyword2.setColor("#000000");
        mTemp.put("keyword2",keyword2);
        //keyword3
        TemplateData keyword3 = new TemplateData();
        keyword3.setValue("0592-5918919");
        keyword3.setColor("#000000");
        mTemp.put("keyword3",keyword3);
        //remark
        TemplateData remark = new TemplateData();
        if(isAgreed) {
            remark.setValue("欢迎您加入开摩邦");
        }else {
            remark.setValue("请确认您的审核资料如有疑议请咨询客服电话");
        }
        remark.setColor("#000000");
        mTemp.put("remark", remark);
        wxTmep.setData(mTemp);
        String jsonTemp = JsonUtils.toJsonString(wxTmep);
        jsonTemp = new String(jsonTemp.getBytes("utf-8"));
        String result = HttpUtils.sendPost(url, jsonTemp);
        return result;
    }
}
